home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1999 March
/
EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso
/
earcd
/
grafica
/
amhelios
/
bitmap24.h
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-01
|
5KB
|
224 lines
#ifndef BITMAP24_H
#define BITMAP24_H
/* -------------------------------------------------------------------------- *\
BITMAP24.H
Copyright © 1997 by Jarno van der Linden
jarno@kcbbs.gen.nz
24 bit bitmap handling, including IFF24 saving
Header file
This program is Freeware, and all usual Freeware rules apply.
21 Feb 1997: Project started
\* -------------------------------------------------------------------------- */
/* -------------------------------- Includes -------------------------------- */
#include <exec/types.h>
#include <dos/dos.h>
/* ------------------------------ Definitions ------------------------------- */
enum {
BITMAP24_ERROR_NONE = 0,
BITMAP24_ERROR_NOBITMAP,
BITMAP24_ERROR_FILEOPEN,
BITMAP24_ERROR_OUTOFBOUNDS
};
/* --------------------------------- Macros --------------------------------- */
/* -------------------------------- Typedefs -------------------------------- */
typedef struct {
UBYTE r;
UBYTE g;
UBYTE b;
} Colour;
/* ------------------------------ Proto Types ------------------------------- */
/* -------------------------------- Structs --------------------------------- */
struct POINT // Raster display point
{
int x; // X-axis co-ordinate
int y; // Y-axis co-ordinate
};
class BitMap24 {
public:
BitMap24(UWORD width,UWORD height);
~BitMap24();
int GetError();
BOOL HasError();
char *GetErrorStr();
UWORD GetWidth();
UWORD GetHeight();
void GetColour(Colour *c,int x,int y);
UBYTE GetRed(int x,int y);
UBYTE GetGreen(int x,int y);
UBYTE GetBlue(int x,int y);
void SetColour(UBYTE r,UBYTE g,UBYTE b,int x,int y);
inline UWORD GetWidthFast();
inline UWORD GetHeightFast();
inline void GetColourFast(Colour *c,int x,int y);
inline UBYTE GetRedFast(int x,int y);
inline UBYTE GetGreenFast(int x,int y);
inline UBYTE GetBlueFast(int x,int y);
inline void SetColourFast(UBYTE r,UBYTE g,UBYTE b,int x,int y);
void WriteBitMap(char *file);
protected:
inline BOOL BoundsCheck(int x,int y);
inline void WriteV(BPTR fh,ULONG v);
inline void WriteB(BPTR fh,UBYTE b);
inline void WriteC(BPTR fh, BYTE b);
inline void WriteP(BPTR fh,void *p,int size);
inline void WriteS(BPTR fh,char *s);
inline UBYTE GatherBits(int row, int c, int b, int x);
inline void WriteRun(BPTR fh, int row, int c, int b, int runstart, int runend);
inline void WriteDump(BPTR fh, int row, int c, int b, int runstart, int runend);
inline void FindRun(int row, int c, int b, int start, int *runstart, int *runlength);
protected:
inline Colour *GetPixelPtr(int x,int y);
protected:
Colour *bitmap;
UWORD width,height;
int bytewidth;
int error;
friend class WinBitmap;
};
#include "color.h"
class WinBitmap
{
public:
WinBitmap()
{
bitmap = NULL;
}
~WinBitmap()
{
;
}
BOOL Open(int w,int h)
{
if(bitmap)
{
delete bitmap;
}
bitmap = new BitMap24((UWORD)w,(UWORD)h);
return !(bitmap->HasError());
}
void Close()
{
if(bitmap)
delete bitmap;
}
void GetPixel(int x,int y, ColorRGB *pc)
{
Colour c;
bitmap->GetColourFast(&c,x,y);
pc->SetBlue((BYTE)(c.b));
pc->SetGreen((BYTE)(c.g));
pc->SetRed((BYTE)(c.r));
}
void SetPixel(int x,int y,ColorRGB &c)
{
UBYTE r,g,b;
b = (UBYTE)(c.GetBlue());
g = (UBYTE)(c.GetGreen());
r = (UBYTE)(c.GetRed());
bitmap->SetColourFast(r,g,b,x,y);
}
int GetWidth()
{
return (int)(bitmap->GetWidthFast());
}
int GetHeight()
{
return (int)(bitmap->GetHeightFast());
}
void SetPixelPtr(int x,int y)
{
curp = bitmap->GetPixelPtr(x,y);
}
void SetCurrPixel(ColorRGB &c)
{
curp->b = c.GetBlue();
curp->g = c.GetGreen();
curp->r = c.GetRed();
}
void IncPixelPtr()
{
curp++;
}
BOOL Write(char *file)
{
bitmap->WriteBitMap(file);
return !(bitmap->HasError());
}
protected:
BitMap24 *bitmap;
Colour *curp;
};
/* -------------------------------- Globals --------------------------------- */
/* ---------------------------------- Code ---------------------------------- */
UWORD BitMap24::GetWidthFast()
{
return width;
}
UWORD BitMap24::GetHeightFast()
{
return height;
}
void BitMap24::GetColourFast(Colour *c,int x,int y)
{
*c = bitmap[y*width+x];
}
UBYTE BitMap24::GetRedFast(int x,int y)
{
return bitmap[y*width+x].r;
}
UBYTE BitMap24::GetGreenFast(int x,int y)
{
return bitmap[y*width+x].g;
}
UBYTE BitMap24::GetBlueFast(int x,int y)
{
return bitmap[y*width+x].b;
}
void BitMap24::SetColourFast(UBYTE r,UBYTE g,UBYTE b,int x,int y)
{
Colour *bp;
bp = &(bitmap[y*width+x]);
bp->r = r;
bp->g = g;
bp->b = b;
}
Colour *BitMap24::GetPixelPtr(int x,int y)
{
return &(bitmap[y*width+x]);
}
#endif /* BITMAP24_H */